package vlms.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import vlms.bean.Movie;
import vlms.service.VLMSServiceProxy;

/**
 * Servlet implementation class DisplayMovie
 */
public class DisplayAllMovies extends HttpServlet {
	private static final long serialVersionUID = 1L;
	VLMSServiceProxy proxy = new VLMSServiceProxy();  
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DisplayAllMovies() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		proxy.setEndpoint("http://localhost:8080/VLMS/services/VLMSService");
		try
		{
			System.out.println("called..");
		HttpSession session = request.getSession(true);
		
		Movie[] movieList=proxy.listAllMovies();
		
		request.setAttribute("MovieList", movieList);
		
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/displayAllMovies.jsp");
		dispatcher.forward(request, response);
		}
		catch(Exception e)
		{
			String message=e.getMessage();
			e.printStackTrace();
			request.setAttribute("message", message);
			RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/adminHome.jsp");
			dispatcher.forward(request, response);
		}
	}

}
